<template>
  <tbody>
      <tr>
          <td>{{obj.id}}</td>
          <td>{{obj.name}}</td>
          <td>{{obj.date|reset }}</td>
          <td>
            <button @click="delbtn(obj.id)">删除</button>
            <button  @click="editbtn(obj.id)" >编辑</button>
          </td>
        </tr>
  </tbody>
</template>

<script>
import axios from 'axios'
import moment from 'moment'

export default {
  props: {
    obj: {
      type: Object,
      require: true
    },
    isdel: {
      type: Array,
      require: true
    }

  },
  data () {
    return {

    }
  },
  filters: {
    reset (date) {
      return moment(date).format('YYYY-MM-DD HH:mm:ss')
    }
  },

  created () {

  },

  methods: {
    async   delbtn (id) {
      console.log(id)

      // console.log(this.isdel.length)
      if (this.isdel.length === 1) return alert('不能再删啦')
      const res = await axios({

        url: '/books/' + id,
        method: 'DELETE'
      })
      console.log(res)
      this.$emit('del-book')
    },
    async editbtn (id) {
      this.isEdit = true
      const res = await axios({
        url: '/books/' + id,
        method: 'GET'
      })

      this.$emit('edname', res.data)
    }

  }
}
</script>

<style scoped lang='less'>

</style>
